package com.novax.ex.activity.provider.handler.provider;

import com.novax.ex.common.constant.MqConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.stereotype.Component;

import jakarta.annotation.Resource;

/**
 * @Description 订单消息生产者
 * @Author zhaolei
 * @Date 2/21/23 4:22 PM
 * @Version 1.0
 */
@Slf4j
@Component
public class MallOrderProvider {
    @Resource
    private AmqpTemplate amqpTemplate;

    /**
     * @description: 发送用户端购买成功
     * @author: Wade
     * @date: 2/21/23 4:31 PM
     * @param: [mallOrder]
     * @return: void
     **/
    public boolean sendBuy(String mallOrder) {
        boolean flag = false;
        try {
            amqpTemplate.convertAndSend(MqConstants.MallOrder.Buy_Success, mallOrder);
            log.info("商品订单消息跟踪sendBuy："+mallOrder);
            flag = true;
        } catch (Exception e) {
            log.error("[用户端购买成功消息异常] msg = {}", mallOrder, e);
        }
        return flag;
    }

    /**
     * @description: 发送抽奖完成消息
     * @author: Wade
     * @date: 2/21/23 4:31 PM
     * @param: [mallOrder]
     * @return: void
     **/
    public boolean sendPrize(String mallOrder) {
        boolean flag = false;
        try {
            amqpTemplate.convertAndSend(MqConstants.MallOrder.Prize_Success, mallOrder);
            log.info("商品订单消息跟踪sendPrize："+mallOrder);
            flag = true;
        } catch (Exception e) {
            log.error("[抽奖完成消息异常] msg = {}", mallOrder, e);
        }
        return flag;
    }

    /**
     * @description: 发送退款消息
     * @author: Wade
     * @date: 2/21/23 4:31 PM
     * @param: [mallOrder]
     * @return: void
     **/
    public boolean sendRedund(String mallOrder) {
        boolean flag = false;
        try {
            amqpTemplate.convertAndSend(MqConstants.MallOrder.Prize_Refund, mallOrder);
            log.info("商品订单消息跟踪sendRedund："+mallOrder);
            flag = true;
        } catch (Exception e) {
            log.error("[退款消息异常] msg = {}", mallOrder, e);
        }
        return flag;
    }
}
